import { customTable } from '@/components/ProTable/interface';
import { ProTableValue } from '@/interface/public';
import { useAddForm } from './use-addForm';
import dayjs from 'dayjs';
/**
 * @name 系统全局配置
 */
export function useDataGrid(proTableBox: ProTableValue) {
  const { addForm } = useAddForm(proTableBox);
  let dataGrid = reactive<customTable>({
    initParam: {},
    // 表格配置项
    columns: [
      { prop: 'operation', label: 'operation', fixed: 'left', width: 140 },
      {
        label: '模板名称',
        prop: 'modelName'
      },
      {
        label: '模板标识',
        prop: 'modelFlag'
      },
      {
        label: '截止时间',
        prop: 'endTime',
        width: 140
      },
      {
        label: '主标题',
        prop: 'title1'
      },
      {
        label: '副标题',
        prop: 'title2'
      },

      {
        label: '状态',
        prop: 'status',
        enum: statusModel,
        tag: true
      },
      {
        label: '备注',
        prop: 'remark'
      }
    ],
    headButtonList: [
      {
        label: 'add',
        type: 'primary',
        icon: 'Plus',
        // permissionCode: "dictionary:save",
        methods: async () => {
          formOpen(addForm, 'add');
        }
      }
    ],
    rowButtonList: [
      {
        label: 'edit',
        type: 'primary',
        display: (row: any) => row.status !== 9,
        // permissionCode: "system:save",
        methods: (row: any) => {
          formOpen(addForm, 'edit', {
            ...row,
            date: dayjs(row.endTime).format('YYYY-MM-DD'),
            time: dayjs(row.endTime).format('HH:mm:ss')
          });
        },
        attrs: {
          link: true
        }
      },

      {
        label: '保存',
        type: 'primary',
        display: (row: any) => row.status !== 0,
        methods: row => {
          const params = { id: row.id };
          useHandleData(modelModelToSave, params, `修改${row.modelName}状态为保存`, proTableBox.value?.getTableList);
        },
        attrs: {
          link: true
        }
      },
      {
        label: '发布',
        type: 'primary',
        display: (row: any) => row.status !== 1,
        methods: row => {
          const params = { id: row.id };
          useHandleData(modelModelToPublish, params, `修改${row.modelName}状态为发布`, proTableBox.value?.getTableList);
        },
        attrs: {
          link: true
        }
      },
      {
        label: '禁用',
        type: 'danger',
        display: (row: any) => row.status !== 9,
        methods: row => {
          const params = { id: row.id };
          useHandleData(modelModelToDisable, params, `修改${row.modelName}状态为禁用`, proTableBox.value?.getTableList);
        },
        attrs: {
          link: true
        }
      }
    ]
  });

  return { dataGrid, addForm };
}
